#!/bin/bash
# Author    : MoShangSan
# create_ts : 2024-02-10
# program   : Compile Code, Convert DOS/Mac text file format into Unix, Tar package

BASH_PATH=$(cd `dirname $0`; pwd)
CURRENT_PATH=$(cd ${BASH_PATH}/../; pwd)
APP_NAME="vocechat_robot_gpt"
LOG_FILE=${CURRENT_PATH}/log/${APP_NAME}_$(date "+%Y%m%d%H%M%S").log
SHELL_NAME="stop.sh"

PORT=2320

function LOG() {
    USER=$(whoami) ####那个用户在操作
    if [ ! -f ${LOG_FILE} ];then
       touch ${LOG_FILE}
    fi
    echo "[${DATE}] ${USER} [$1][$SHELL_NAME]$2"
    echo "[${DATE}] ${USER} [$1][$SHELL_NAME]$2" >> ${LOG_FILE}  ######（$0脚本本身，$@将参数作为整体传输调用, >> 将输出结果以追加的方式添加重定向到本地文件中）
}

# 启动机器人gpt服务
# python3 xiaogpt-main/xiaogpt.py --config xiao_config.json
# if [ $? -ne 0 ]
#     LOG ERROR "xiaogpt start fail"  
# fi

# 启动机器人websocket服务
SERVER_NUM=$(ps aux | grep "$PORT" | grep -v grep | wc -l)
if [ ${SERVER_NUM} -ne 0 ];then
    LOG INFO "chat_server is running"
    kill -9 ${SERVER_NUM}
    if [ $? -ne 0 ]
        LOG ERROR "${SERVER_NUM} kill fail"
        exit 1
    fi
fi
exit 0